package utils

import (
	"encoding/json"
	"log"
	"webcppcluster/config"
)

// ErrResult 错误返回结果
func ErrResult(code int, reason string) []byte {
	result := map[string]interface{}{
		"code":   code,
		"reason": reason,
	}
	jsonBytes, _ := json.Marshal(result)
	return jsonBytes
}

// SuccessResult 成功返回结果
func SuccessResult(data interface{}) []byte {
	result := map[string]interface{}{
		"code": config.ECReqNormal,
	}
	if data != nil {
		for k, v := range data.(map[string]interface{}) {
			result[k] = v
		}
	}
	jsonBytes, _ := json.Marshal(result)
	return jsonBytes
}

// LogError 记录错误日志
func LogError(err error) {
	if err != nil {
		log.Printf("Error: %v", err)
	}
}

// LogErrorWithMessage 记录错误日志和消息
func LogErrorWithMessage(message string, err error) {
	if err != nil {
		log.Printf("%s: %v", message, err)
	}
}


